﻿using FrameworkCore.Extensions;
using FrameworkCore.Migrations.Data;
using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.Entities;

/// <summary>
/// 用户表
/// </summary>
[Table("Customers")]
public partial class Customer : BaseAuditableEntity, ISoftDeletedEntity
{
    /// <summary>
    /// 用户名
    /// </summary>
    [Column("Username")]
    public string? Username { get; set; }

    /// <summary>
    /// 哈希密码
    /// </summary>
    public string? PasswordHash { get; set; }

    /// <summary>
    /// 电子邮箱
    /// </summary>
    public string? Email { get; set; }

    /// <summary>
    /// 头像
    /// </summary>
    public string? Avatar { get; set; }


    /// <summary>
    /// 删除标志
    /// </summary>
    public bool? IsDeleted { get; set; }

    /// <summary>
    /// 将密码转换为哈希值并存储
    /// </summary>
    /// <param name="password">密码</param>
    public void HashPassword(string password)
    {
        PasswordHash = password.MDString();
    }

    /// <summary>
    /// 验证密码是否匹配
    /// </summary>
    /// <param name="password">要比较的密码</param>
    /// <returns>如果密码匹配则返回 true，否则返回 false</returns>
    public bool VerifyPassword(string password)
    {
        return PasswordHash == password.MDString();
    }
}